package com.boco.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.entity.EMR_MJZFYSFXMMX;

public class GetEMR_MJZFYSFXMMXData {
	
	private static final Log log = LogFactory.getLog(GetEMR_MJZFYSFXMMXData.class);
	public static List<EMR_MJZFYSFXMMX> getData()
	{
	    Connection con = null;
	    PreparedStatement pre = null;
	    ResultSet result = null;
	    List<EMR_MJZFYSFXMMX> re = new ArrayList<EMR_MJZFYSFXMMX>();
	    try
	    {
	        Class.forName("oracle.jdbc.driver.OracleDriver");
	        System.out.println("开始尝试连接数据库！");
	        String url = "jdbc:oracle:" + "thin:@172.20.21.12:1521:orcl";
	        String user = "sjzx_hxk";
	        String password = "boco#1234";
	        con = DriverManager.getConnection(url, user, password);
	        System.out.println("连接成功！");
	        
	        String sql = "select "
	        		+"a.sfmxid as SFMXDM,"
					+"b.jzlsh as MJZH,"
					+"a.yljgdm as YLJGZZJGDM,"
					+"'' as HZZSYH,"
					+"b.jsfph as FPBH,"
					+"'' as SJBH,"
					+"a.mxxmbm as SFXMDM,"
					+"a.mxxmmc as SFXMMC,"
					+"a.mxxmdw as SFXMDW,"
					+"trunc(a.mxxmdj, 3) as SFXMDJ,"
					+"trunc(a.mxxmsl, 0) as SFXMSL,"
					+"trunc(a.mxxmssje, 3) as SFXMJE,"
					+"'' as FYLBDM,"
					+"a.xmflmc as FYLBMC,"
					+"'' as  ZRLSH,"
					+"to_char(a.ywscsj,'YYYY-MM-dd HH24:mi:ss') as BCRQ,"
					+"'' as ORGCODE,"
					+"'' as AREACODE,"
					+"to_char(sysdate,'yyyyMMddHH24miss') as UPLOADTIME,"
					+"'' as  SOURCEID "
					+"from TB_MZ_SFMXB a left join "
					+" TB_MZ_JSB b on a.yljgdm = b.yljgdm and"
					+" a.jzlsh = b.jzlsh ";
	 
	        log.info("查询sql："+sql);
	        pre = con.prepareStatement(sql);
	        result = pre.executeQuery();
	        System.out.println("执行成功");
	        while (result.next()){
//	            System.out.println(result.getInt("YYDAH"));
	        	EMR_MJZFYSFXMMX temp = new EMR_MJZFYSFXMMX();
	        	temp.setSFMXDM(result.getString("SFMXDM"));
	        	temp.setMJZH(result.getString("MJZH"));
	        	temp.setYLJGZZJGDM(result.getString("YLJGZZJGDM"));
	        	temp.setHZZSYH(result.getString("HZZSYH"));
	        	temp.setFPBH(result.getString("FPBH"));
	        	temp.setSJBH(result.getString("SJBH"));
	        	temp.setSFXMDM(result.getString("SFXMDM"));
	        	temp.setSFXMMC(result.getString("SFXMMC"));
	        	temp.setSFXMDW(result.getString("SFXMDW"));
	        	temp.setSFXMDJ(result.getString("SFXMDJ"));
	        	temp.setSFXMSL(result.getString("SFXMSL"));
	        	temp.setSFXMJE(result.getString("SFXMJE"));
	        	temp.setFYLBDM(result.getString("FYLBDM"));
	        	temp.setFYLBMC(result.getString("FYLBMC"));
	        	temp.setZRLSH(result.getString("ZRLSH"));
	        	temp.setBCRQ(result.getString("BCRQ"));
	        	temp.setORGCODE(result.getString("ORGCODE"));
	        	temp.setAREACODE(result.getString("AREACODE"));
	        	temp.setUPLOADTIME(result.getString("UPLOADTIME"));
	        	temp.setSOURCEID(result.getString("SOURCEID"));
	        	re.add(temp);
	        }
	    }
	    catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    finally
	    {
	        try
	        {
	            if (result != null)
	                result.close();
	            if (pre != null)
	                pre.close();
	            if (con != null)
	                con.close();
	            System.out.println("数据库连接已关闭！");
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace();
	        }
	    }
		return re;
	}
}
